﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class export_studentExport : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string student_id = "";
        string student_name = "";

        System.Data.DataTable table1 = new System.Data.DataTable();
        int count = 0;//总记录的条数
        try
        {
            
            if (Request.QueryString["student_id"] != null)
            {
                student_id = Request.QueryString["student_id"].ToString().Trim();
            }
            if (Request.QueryString["student_name"] != null)
            {
                student_name = Request.QueryString["student_name"].ToString().Trim();
            }

            
            List<string> wheres = new List<string>();

            if (student_id != "")
            {
                wheres.Add("student_id like '%" + student_id + "%'");
            }
            if (student_name != "")
            {
                wheres.Add("student_name like '%" + student_name + "%'");
            }
            string wh = "";
            if (wheres.Count > 0)
            {
                wh = string.Join(" and ", wheres.ToArray());
                
            }
            
            string sql = "select  a.student_id ,a.student_name ,c.college_name, b.major_name,a.student_sex,a.student_tel,a.student_id_card from tb_student as a "
            + " inner join tb_major as b on a.major_id=b.major_id "
            + "inner join tb_college as c on b.college_id = c.college_id";

            if (wheres.Count > 0)
            {
                sql = sql + " where " + wh ;
            }
            
            table1 = SqlServer.GetDataTable(sql);
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('有错误')</script>");
            Response.End();
        }
       
        Response.Write(Json.ToJson(table1, count));
        Response.End();

    }


}